﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using WMI.root.cimv2;
using System.Diagnostics;

public partial class System_MemoryStatus : System.Web.UI.Page
{
    protected GlobalMemoryStatus Memory { get; private set; }
    protected int PhysProcentage
    {
        get
        {
            return (int)Others.CalculateProcentage(Memory.AvailablePhysical, Memory.TotalPhysical);
        }
    }


    protected int PageFileProcentage
    {
        get
        {
            return (int)Others.CalculateProcentage(Memory.AvailablePageFile, Memory.TotalPageFile);
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        Memory = GlobalMemoryStatus.Get();

        var q = from p in Process.GetProcesses()
                orderby p.WorkingSet64 descending
                select new
                {
                    Name = p.ProcessName,
                    Session=p.SessionId,
                    WorkingSet = Others.FormatSize((ulong)p.WorkingSet64)                    
                };
        q = q.Take(10);
        
        lvProcesses.DataSource = q;
        lvProcesses.DataBind();
    }
}
